
import { registerClass } from "../../../cfw/tools/class_decorator";
import { NativeInterstitialAd } from "../../native/native";
import BaseAd from "../../core/base/BaseAd";
import { SDKLogicState, SDKState } from "../../SDKDefine";

@registerClass('MiMoInsertAd')
export default class MiMoInsertAd extends BaseAd {
    hide(): void {
        throw new Error("Method not implemented.");
    }

    load(): void {
        if (this.ad) {
            this.ad.load();
        }
    }
    show(): void {
        if (this.ad) {
            this.ad.show();
        }
    }

    protected ad: NativeInterstitialAd;
    // open() {
    //     this.preload(SDKState.open);


    // }
    create() {
        if (!this.ad) {
            this.ad = this.sdk.createInterstitialAd({
                adUnitId: this.adUnitID
            })
            this.ad.onLoad(this.getFunc(this.onLoad))
            this.ad.onError(this.getFunc(this.onError))
        }
    }
    onLoad() {
        this.setState(SDKState.loadSucess)
    }

    onError(err: any) {
        this.setState(SDKState.loadFail)
    }

    destroy(): void {
        if (this.ad) {
            this.ad.offLoad(this.getFunc(this.onLoad))
            this.ad.offError(this.getFunc(this.onError))
            this.ad.destroy()
            this.ad = null;
        }
    }

}
